package com.netflix.loadbalancer;

import com.netflix.client.ClientFactory;
import com.netflix.client.IClientConfigAware;
import com.netflix.client.ClientException;
import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig;

public abstract class AbstractServerList<T extends Server> implements ServerList<T>, IClientConfigAware {

    public AbstractServerListFilter<T> getFilterImpl(IClientConfig niwsClientConfig) throws ClientException {
        String niwsServerListFilterClassName = null;
        try {
            niwsServerListFilterClassName = niwsClientConfig.get(CommonClientConfigKey.NIWSServerListFilterClassName, ZoneAffinityServerListFilter.class.getName());
            AbstractServerListFilter<T> abstractNIWSServerListFilter = (AbstractServerListFilter<T>) ClientFactory.instantiateInstanceWithClientConfig(niwsServerListFilterClassName, niwsClientConfig);
            return abstractNIWSServerListFilter;
        } catch (Throwable e) {
            throw new ClientException(ClientException.ErrorType.CONFIGURATION, "Unable to get an instance of CommonClientConfigKey.NIWSServerListFilterClassName. Configured class:" + niwsServerListFilterClassName, e);
        }
    }
}
